package com.yh.servlet.admin;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yh.service.UserService;
import com.yh.service.impl.UserServiceImpl;
import com.yh.vo.UserVO;
import com.yh.vo.ZhanfengVO;

@WebServlet("/admin/user-page-key-two.let")
public class UserPageKeyTwoServlet extends HttpServlet{

	private UserService userService = new UserServiceImpl();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		int index = 0;// 起始索引
		int pageSize = 5;// 每页的记录条数
		int p = 1;
		if (req.getParameter("pageSize") != null) {
			pageSize = (Integer.valueOf(req.getParameter("pageSize")));
		}
		if (req.getParameter("index") != null) {
			p = Integer.valueOf(req.getParameter("index"));// 当前页数
			index = (Integer.valueOf(req.getParameter("index")) - 1) * pageSize;
		}
//		System.out.println("index"+index);
//		System.out.println("p"+p);
		String key = req.getParameter("key");
		List<UserVO> list = userService.keylistTwo(key, index, pageSize);
		Long count = userService.keyCount(key);
		int pages = (int) ((count - 1) / pageSize + 1);
		req.setAttribute("list", list);
		req.setAttribute("pages", pages);
		req.setAttribute("p", p);
		req.setAttribute("key", key);
		req.setAttribute("pageSize", pageSize);
		req.getRequestDispatcher("/admin/user-page-key-two.jsp").forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
	
}
